package tree;

/**
 * 数组转换二叉树
 */
public class ArrBinaryTreeDemo {
    public static void main(String[] args) {
        int[] arr = new int[]{1,2,3,4,5,6,7};
        ArrBinaryTree a = new ArrBinaryTree(arr);
        a.preOrder();
    }
}
class ArrBinaryTree{
    int[] arr ;
    ArrBinaryTree(int[] arr){
        this.arr=arr;
    }
    public void preOrder(){
        preOrder(0);
    }
    public void preOrder(int index){

        if(2*index+1<arr.length){
            preOrder(2*index+1);
        }
        System.out.println(arr[index]);
        if(2*index+2<arr.length){
            preOrder(2*index+2);
        }
    }
}
